package com.eugene.ui.commands;

import org.eclipse.core.commands.AbstractHandler;
import org.eclipse.core.commands.ExecutionEvent;
import org.eclipse.core.commands.ExecutionException;
import org.eclipse.jface.viewers.ISelection;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.TableViewer;
import org.eclipse.ui.IEditorPart;
import org.eclipse.ui.IEditorReference;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchPart;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.handlers.HandlerUtil;

import com.eugene.ui.editors.IrCurveEditor;
import com.eugene.ui.views.MarketVariablePropertyView;

public class ShowColumn extends AbstractHandler{
	private TableViewer tableViewer;
//	private List<CommonEntity> intRateHis = new ArrayList<CommonEntity>();
	private final String id = "com.eugene.ui.views.MarketVariableView";
	
	@Override
	public Object execute(ExecutionEvent event) throws ExecutionException {
		// Get the active Part
		IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindow(event);
		IWorkbenchPage page = window.getActivePage();
		IWorkbenchPart part = page.getActivePart();
		IEditorPart editPart = page.getActiveEditor();
		
		IrCurveEditor irEdit;
		if(editPart.getClass().toString().contains("IrCurveEditor")){
			irEdit = (IrCurveEditor) editPart;
			irEdit.getTableViewer().getTable().getColumn(1).setWidth(0);
//			table.setColumnSelectionAllowed(true);
			System.out.println("TEst" + irEdit.getTableViewer().getTable().getSelectionIndex());
//			System.out.println("TEst" + irEdit.getTableViewer().getTable().getc
//					);
		}
		
		// Get the selection
		ISelection selection = part.getSite().getSelectionProvider().getSelection();
		System.out.println("Test 20 : in the Execution" +tableViewer.toString());
		if (selection != null && selection instanceof IStructuredSelection) {
			Object obj = ((IStructuredSelection) selection).getFirstElement();
			
			System.out.println("Test Command" + selection.toString());
			// If we had a selection lets open the editor
			if (obj != null && part instanceof TableViewer) {
				System.out.println("Test Command");
				tableViewer = (TableViewer)part;
			}
			System.out.println("Test Command 2");
		}
		return null;
	}

}
